﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Bpms.Data;
using Bpms.Entity;
using Bpms.Log;
using Bpms.Cache;

namespace Bpms.Bll
{
    public class Contact
    {
        #region Member
        /// <summary>
        /// 数据库改动事件委托
        /// </summary>
        public delegate void DBChangedEventHandler();

        /// <summary>
        /// 日志事件委托
        /// </summary>
        public delegate void LogEventHandler();

        /// <summary>
        /// 数据库改动事件
        /// </summary>
        public static event DBChangedEventHandler DBChanged;

        /// <summary>
        /// 写日志事件
        /// </summary>
        public static event LogEventHandler WriteLog;

        #region Private

        private static IDataProvider provider = DatabaseProvider.GetInstance();

        /// <summary>
        /// 数据改动事件处理函数
        /// </summary>
        static void OnDBChanged()
        {
            if (DBChanged != null)
            {
                DBChanged();
            }
        }

        /// <summary>
        /// 写日志处理函数
        /// </summary>
        static void OnWriteLog()
        {
            if (WriteLog != null)
            {
                WriteLog();
            }
        }

        #endregion

        #endregion

        /// <summary>
        /// 添加联系人
        /// </summary>
        /// <param name="contact">联系人实体</param>
        /// <returns>添加是否成功（true：成功，false：失败）</returns>
        public static bool InsertContact(ContactInfo contact)
        {
            return provider.InsertContact(contact);
        }

        /// <summary>
        /// 修改联系人
        /// </summary>
        /// <param name="contact">联系人实体</param>
        /// <returns>修改是否成功（true：成功，false：失败）</returns>
        public static bool UpdateContact(ContactInfo contact)
        {
            return provider.UpdateContact(contact);
        }

        /// <summary>
        /// 删除联系人
        /// </summary>
        /// <param name="contactId">联系人ID</param>
        /// <returns>删除是否成功（true：成功，false：失败）</returns>
        public static bool DeleteContact(int contactId)
        {
            return provider.DeleteContact(contactId);
        }

        /// <summary>
        /// 得到联系人信息
        /// </summary>
        /// <param name="contactId">联系人ID</param>
        /// <returns>联系人信息</returns>
        public static ContactInfo GetContact(int contactId)
        {
            return provider.GetContact(contactId);
        }

        /// <summary>
        /// 得到联系人列表
        /// </summary>
        /// <param name="pageId">当前页ID</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="condition">提取的条件</param>
        /// <returns>联系人列表</returns>
        public static IList<ContactInfo> GetContacts(int pageId, int pageSize, string condition)
        {
            return provider.GetContacts(pageId, pageSize, condition);
        }

        /// <summary>
        /// 得到联系人列表
        /// </summary>
        /// <param name="condition">提取的条件</param>
        /// <returns>联系人列表</returns>
        public static IList<ContactInfo> GetContacts(string condition)
        {
            return provider.GetContacts(condition);
        }


    }
}
